package me.fangsong.timefold.line.domain;

import ai.timefold.solver.core.api.domain.entity.PlanningEntity;
import ai.timefold.solver.core.api.domain.lookup.PlanningId;
import ai.timefold.solver.core.api.domain.variable.PlanningListVariable;

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * 产线
 */
@PlanningEntity
public class Line {
    @PlanningId
    private Integer id;

    private String name;

    private LocalTime morningStartTime;

    private LocalTime morningEndTime;

    private LocalTime afternoonStartTime;

    private LocalTime afternoonEndTime;

    @PlanningListVariable
    private List<Work> workList = new ArrayList<>();

    public Line() {
    }

    public Line(Integer id, String name, LocalTime morningStartTime, LocalTime morningEndTime, LocalTime afternoonStartTime, LocalTime afternoonEndTime) {
        this.id = id;
        this.name = name;
        this.morningStartTime = morningStartTime;
        this.morningEndTime = morningEndTime;
        this.afternoonStartTime = afternoonStartTime;
        this.afternoonEndTime = afternoonEndTime;
    }

    public Integer getWorkListMinutes(){
        int totalWorkMinutes = 0;
        for (Work work : workList) {
            totalWorkMinutes += work.getWorkMinute();
        }
        return totalWorkMinutes;
    }

    public Long getTotalWorkMinute(){
        return ChronoUnit.MINUTES.between(morningStartTime, morningEndTime)+ChronoUnit.MINUTES.between(afternoonStartTime, afternoonEndTime);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LocalTime getMorningStartTime() {
        return morningStartTime;
    }

    public void setMorningStartTime(LocalTime morningStartTime) {
        this.morningStartTime = morningStartTime;
    }

    public LocalTime getAfternoonEndTime() {
        return afternoonEndTime;
    }

    public void setAfternoonEndTime(LocalTime afternoonEndTime) {
        this.afternoonEndTime = afternoonEndTime;
    }

    public LocalTime getMorningEndTime() {
        return morningEndTime;
    }

    public void setMorningEndTime(LocalTime morningEndTime) {
        this.morningEndTime = morningEndTime;
    }

    public LocalTime getAfternoonStartTime() {
        return afternoonStartTime;
    }

    public void setAfternoonStartTime(LocalTime afternoonStartTime) {
        this.afternoonStartTime = afternoonStartTime;
    }

    public List<Work> getWorkList() {
        return workList;
    }

    public void setWorkList(List<Work> workList) {
        this.workList = workList;
    }
}
